<template>
  <view class="page_content">
    <scroll-view scrollY="true"
      class="scroll_box"
      v-if="listData.length"
      @scrolltolower="lower">
      <view class="user_item" v-for="(item,index) in listData" :key="index" @tap="gotoDetail(item.id,item.uid)">
        <view class="item_left">
          <view>{{styleList.find(x => x.id == item.style).name}}</view>
          <view>{{item.create_time}}</view>
        </view>
        <view class="item_right color_orange" v-if="item.type == 1">+{{item.num}}</view>
        <view class="item_right" v-else-if="item.type == 2">-{{item.num}}</view>
        <view class="item_right" v-else>{{item.num}}</view>
      </view>
      <AtLoadMore style="height:30px;margin-top:-10px" noMoreText="没有更多了" :status="loadingStatus"/>
    </scroll-view>
  </view>
</template>

<script>
import Taro from '@tarojs/taro'
import './userPoint.module.scss'
import UserAPI from '../../../api/user'
export default {
  name: 'userList',
  data(){
    return{
      listData: [],
      total: 0,
      page: 1,
      loadingStatus: "more",
      showLoading: false, // 上滑加载更多
      styleList: [ // 积分变动原因
        { id: 0, name: "签到送积分" },
        { id: 1, name: "线下买单" },
        { id: 2, name: "充值" },
        { id: 3, name: "后台变动" },
        { id: 4, name: "回退" },
        { id: 5, name: "其他" },
        { id: 6, name: "积分兑换" },
        { id: 7, name: "邀请新人" },
        { id: 8, name: "员工变动" }
      ],
      firstIn: true,
    }
  },
  mounted(){
    this.init();
  },
  methods:{
    init(){
      this.getListData()
    },
    async getListData(){
      var data = {
        app_id: Taro.getStorageSync('app_id'),
        page: this.page,
        uid: Taro.getStorageSync('detail_uid')
      }
      const res = await UserAPI.userPointLog(data);
      if(res.code == 200){
        this.total = res.data.total;
        if(res.data.data){
          res.data.data.forEach(item => {
            this.listData.push(item)
          })
        }
        this.showLoading = false;
        this.page ++;
        if(this.total == this.listData.length){
          this.loadingStatus = 'noMore';
        }else{
          if(this.firstIn){
            this.getListData();
          }
        }
        console.log("this.loadingStatus",this.loadingStatus);
      }
    },
    lower(e) { // 到底加载更多
      console.log(e)
      if(!this.showLoading){
        if(this.total != this.listData.length){
          this.showLoading = true;
          this.loadingStatus = 'loading'
          this.getListData();
        }
      }
    },
  },
}
</script>